<?php


namespace app\app\controller\sys;


use app\model\MenuModel;
use app\services\Permission;

class Menu
{
    /**
     * @Permission(action="sys:menu:lst")
     */
    public function lst(){
        $menuModel = new MenuModel();
        $where=[['deleted','=',0]];
        $mlst = $menuModel->where($where)->order('sort_number asc')->select();
        return success($mlst);
    }

    /**
     * @Permission(action="sys:menu:add")
     */
    public function add(){
        $menuModel = new MenuModel();
        $_menu = json_decode(input('menu'), true);
        $_menu['add_time']=time();
        $res = $menuModel::create($_menu);
        return $res ? success(null,0,"添加成功") : error(1,"添加失败");
    }

    /**
     * @Permission(action="sys:menu:edt")
     */
    public function edt(){
        $menuModel = new MenuModel();
        $_menu = json_decode(input('menu'), true);
        $_menu['edt_time']=time();
        $res = $menuModel::update($_menu);
        return $res ? success(null,0,"修改成功") : error(1,"修改失败");
    }

    /**
     * @Permission(action="sys:menu:del")
     */
    public function del(){
        $menuModel = new MenuModel();
        $_menu_id = input("menu_id");
        $where[]=['menu_id','in',strval($_menu_id)];
        $res = $menuModel->where($where)->update(["deleted"=>1]);
        return $res ? success(null,0,"删除成功") : error(1,"删除失败");
    }
}